package
{
	import flash.display.*;
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.display3D.IndexBuffer3D;
	import flash.events.*;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.*;
	import flash.net.FileReference;
	import flash.net.LocalConnection;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.ui.Mouse;
	import flash.utils.ByteArray;
	import flash.utils.Timer;
	
	import flashx.textLayout.operations.MoveChildrenOperation;
	public class LogoDecode extends Sprite
	{
		private var _logoImage:OrigImage;
		private var _logoBitData:BitmapData;
		private var _viewWidth=1024;
		private var _viewHeight=768;
		private var _xWidth:int=28;
		private var _yHeight:int=28;
		private var _spArray:Array=[];
		private var _btDataArray:Array=[];
		private var _positionArr:Array=[];
		
		public function LogoDecode()
		{
			_logoImage=new OrigImage(false);
			_logoImage.path="image/Logo/AVANICER.png";
			this.addChild(_logoImage);
			_logoImage.addEventListener(Event.COMPLETE,LoadFinish);
			trace("start");	
		}
		
		protected function  LoadFinish(event:Event):void
		{
			_logoBitData=_logoImage.bmpData;
			Decode();
		}
		public function  get PositionArray():Array{
				return _positionArr;
		}
		public function Decode():void
		{
			var cutBimapdata:BitmapData = new BitmapData(150, 150);
			var rect:Rectangle = new Rectangle(0, 0, 150, 150);//裁剪的区域大小
			var pt:Point = new Point(0, 0);
			cutBimapdata.copyPixels(_logoBitData, rect, pt);
			//将borignBitmapData中以pt为左上顶点的rect矩形像素复制到cutBimapdata中 实现裁剪
			var cutBimap:Bitmap = new Bitmap(cutBimapdata);
			this.addChild(cutBimap);//添加裁剪之后的图片
			cutBimap.y=500;
			var xNum:int=Math.ceil( _logoBitData.width/_xWidth);
			var yNum:int=Math.ceil(_logoBitData.height/_yHeight);
			trace("xNum="+xNum+"  yNum="+yNum);
			for(var i:int=0;i<xNum;i++){
				for(var j:int=0;j<yNum;j++){
					var cutBimapdata:BitmapData = new BitmapData(_xWidth, _yHeight);
					var rect:Rectangle = new Rectangle(i*_xWidth,j*_yHeight , _xWidth, _yHeight);//裁剪的区域大小
					var pt:Point = new Point(0, 0);
					cutBimapdata.copyPixels(_logoBitData, rect, pt);
					//将borignBitmapData中以pt为左上顶点的rect矩形像素复制到cutBimapdata中 实现裁剪
					var cutBimap:Bitmap = new Bitmap(cutBimapdata);
					this.addChild(cutBimap);//添加裁剪之后的图片
					cutBimap.x=i*(_xWidth+1);
					cutBimap.y=j*(_yHeight+1)+200;
					_spArray.push(cutBimap);
					_btDataArray.push(cutBimapdata);
				}
			}
			var centerX:int =_xWidth/2;
			var centerY:int=_yHeight/2;		
			for(var num:int=0;num<_btDataArray.length;num++){
				if(_btDataArray[num].getPixel32(centerX,centerY).toString(16)=="ffffffff"){//模块中心没有颜色，删除
					this.removeChild(_spArray[num]);
					
				}else{
					var point:Point=new Point();
					point.x=_spArray[num].x;
					point.y=_spArray[num].y;
					_positionArr.push(point);
				}
			}
		}
		
	
	}
}